//
//  CustomTabBarController.m
//  LOLProject
//
//  Created by SXW on 16/3/23.
//  Copyright © 2016年 盛宣伟. All rights reserved.
//

#import "CustomTabBarController.h"
#import "CustomNavigationController.h"
#import "TabBarItem.h"
@interface CustomTabBarController ()

@property (nonatomic, strong)NSArray *itemArray;

@end

@implementation CustomTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _itemArray = [NSArray arrayWithObjects:[TabBarItem withForSet:@"FisrtViewController" icon:@"tab_icon_news_normal" select:@"tab_icon_news_press" iconName:@"首页"],[TabBarItem withForSet:@"ChanViewController" icon:@"tab_icon_quiz_normal" select:@"tab_icon_quiz_press" iconName:@"分类"],[TabBarItem withForSet:@"HeroViewController" icon:@"tab_icon_friend_normal" select:@"tab_icon_friend_press" iconName:@"英雄"],[TabBarItem withForSet:@"InformationViewController" icon:@"tab_icon_more_normal" select:@"tab_icon_more_press" iconName:@"资讯"],nil];
    
    //想通过循环来做
    [self createItem];
    
    //整体设置tabbar的颜色和字体
    NSDictionary *dic = @{NSForegroundColorAttributeName:[UIColor colorFromHexRGB:@"000000"],NSFontAttributeName:[UIFont systemFontOfSize:15]};
    [[UITabBarItem appearance] setTitleTextAttributes:dic forState:UIControlStateSelected];
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorFromHexRGB:@"000000"]];
}

- (void)createItem{
    
    for (int i = 0; i < _itemArray.count; i++) {
        //取出array里面的tabbaritem对象
        TabBarItem *item = _itemArray[i];
        //通过runntime 取到class 对象
        Class class = NSClassFromString(item.className);
        
        UIViewController *controller = [[class alloc] init ];
        controller.tabBarItem.title = item.iconName;
        controller.tabBarItem.image = [[UIImage imageNamed:item.icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //        controller.tabBarItem.selectedImage = [[UIImage imageNamed:item.selectIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        controller.tabBarItem.selectedImage = [UIImage imageNamed:item.selectIcon];
        CustomNavigationController *nav = [[CustomNavigationController alloc] initWithRootViewController:controller];
        [self addChildViewController:nav];
        
    }
}







@end
